package com.beichuan_travel.model.vo;

import com.beichuan_travel.enums.ResultCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;

@Getter
@ApiModel(description = "封装的返回响应体")
public class ResultVO<T> {

    @ApiModelProperty(value = "返回的状态码", notes = "默认1000成功")
    private int code;

    @ApiModelProperty(value = "响应信息", notes = "若操作成功则返回success")
    private String msg;

    @ApiModelProperty(value = "响应体", notes = "若无响应体则返回null")
    private T data;

    public ResultVO(ResultCode resultCode, T data) {
        this.code = resultCode.getStatusCode();
        this.msg = resultCode.getMsg();
        this.data = data;
    }

    public ResultVO(T data) {
        this(ResultCode.SUCCESSED,data);
    }

    public ResultVO(ResultCode resultCode) {
        this.code = resultCode.getStatusCode();
        this.msg = resultCode.getMsg();
        this.data = null;
    }

    @Override
    public String toString() {
        return String.format("{\"code\":%d,\"msg\":\"%s\",\"data\":\"%s\"}", code, msg, data.toString());
    }
}
